package com.jacobson.huobi.utils

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.view.Gravity
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import com.bumptech.glide.Glide
import com.jacobson.huobi.R

object BigImgUtil {
    /**
     * 打开大图
     */
    public fun openBigImg(context: Context, imgUrl: String) {
        var imgDialog = Dialog(context)
        var imgLayout = getImgLL(context, imgUrl)
        imgDialog.setContentView(imgLayout)
//        var attr = WindowManager.LayoutParams()
//        attr.width = WindowManager.LayoutParams.MATCH_PARENT
//        attr.height = WindowManager.LayoutParams.MATCH_PARENT
//        imgDialog.window.attributes = attr
        imgDialog.window.decorView.setPadding(0, 0, 0, 0)
        imgDialog.window.decorView.setBackgroundColor(Color.TRANSPARENT)
        imgDialog.show()
        imgDialog.setCanceledOnTouchOutside(true)
        imgLayout.setOnClickListener {
            imgDialog.dismiss()
        }
    }

    private fun getImgLL(context: Context, imgUrl: String): LinearLayout {
        var ll = LinearLayout(context)
        ll.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        ll.gravity = Gravity.CENTER
        ll.setHorizontalGravity(Gravity.CENTER)
        ll.setVerticalGravity(Gravity.CENTER)
        var img = ImageView(ll.context)
        Glide.with(context).load(imgUrl).into(img)
        img.layoutParams = ViewGroup.LayoutParams(800, 800)

        ll.addView(img)
        return ll
    }
}